package org.gis.utils.dps;


import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author gus
 */

public class XmlBeanLoader 
{
   
    public static  void serialize(DynamicPropertySet bean, OutputStream os) throws Exception
    {
        XStream  stream = new XStream();
        stream.registerConverter(new DynamicPropertySetConverter(bean.getClass()));
        stream.alias("DynamicPropertySet", DynamicPropertySetBaseMap.class);
        stream.toXML(bean, os);
    }
    
    public static  void serialize(DynamicPropertySet bean, StringBuilder builder) throws Exception
    {
        XStream  stream = new XStream();
        stream.registerConverter(new DynamicPropertySetConverter(bean.getClass()));
        stream.alias("DynamicPropertySet", DynamicPropertySetBaseMap.class);
        builder.append(stream.toXML(bean));
    }
    
    public static DynamicPropertySet deserialize(InputStream is, Class<? extends DynamicPropertySet> type) throws Exception
    {
        XStream stream  = new XStream(new DomDriver());
        stream.registerConverter(new DynamicPropertySetConverter(type)); 
        stream.alias("DynamicPropertySet", DynamicPropertySetBaseMap.class);
        return  (DynamicPropertySet) stream.fromXML(is);
    }

    public static DynamicPropertySet deserialize(String str, Class<? extends DynamicPropertySet> type) throws Exception
    {
        XStream stream  = new XStream(new DomDriver());
        stream.registerConverter(new DynamicPropertySetConverter(type)); 
        stream.alias("DynamicPropertySet", DynamicPropertySetBaseMap.class);
        return  (DynamicPropertySet) stream.fromXML(str);
    }
}
